package com.yinhai.msg.wechat.rest;

import com.yinhai.msg.wechat.domain.WechatPo;
import com.yinhai.msg.wechat.service.read.WechatReadService;
import com.yinhai.msg.wechat.service.write.WechatWriteService;
import com.yinhai.ta404.core.restservice.BaseRestService;
import com.yinhai.ta404.core.utils.ValidateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @File xxx
 * @Author Administrator
 * @Date 2019/5/20 0020 16:10
 * @Version 1.0
 * @Description xxx
 */
@RestController
@RequestMapping("wechat")
public class WechatRestService extends BaseRestService {
    @Autowired
    private WechatWriteService wechatWriteService;
    @Autowired
    private WechatReadService wechatReadService;

    /**
     * 查询微信配置列表
     * @return
     */
    @PostMapping("queryWechatList.do")
    public List queryWechatList(){
        return null;
    }

    /**
     * 保存当前微信配置
     * @param wechatPo
     */
    @PostMapping("saveWechat.do")
    public void saveWechat(WechatPo wechatPo){
        wechatPo.setCreateUser(getCurUserAccount().getUsername());
        if(ValidateUtil.isEmpty(wechatPo.getId())){
            wechatPo.setId(UUID.randomUUID().toString());
            wechatPo.setCreateTime(new Date());
        }
        wechatPo.setUpdateTime(new Date());
        if("1".equals(wechatPo.getDefaultWx())){
            wechatWriteService.removeWechatNoDefault();
        }
        wechatWriteService.saveWechat(wechatPo);
        setSuccess(true);
    }
}
